package com.tour.service.impl;

import com.tour.bean.ReturnT;
import com.tour.bean.UserHotel;
import com.tour.dao.UserHotelMapper;
import com.tour.service.UserHotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * user_hotel
 * @author
 * @date 2020/03/16
 */
@Service
public class UserHotelServiceImpl implements UserHotelService {

    @Autowired
    private UserHotelMapper userHotelMapper;


    @Override
    public ReturnT<String> insert(UserHotel userHotel) {

        // valid
        if (userHotel == null) {
            return new ReturnT<String>(ReturnT.FAIL_CODE, "必要参数缺失");
        }

        userHotelMapper.insert(userHotel);
        return ReturnT.SUCCESS;
    }


    @Override
    public ReturnT<String> delete(int id) {
        int ret = userHotelMapper.delete(id);
        return ret>0?ReturnT.SUCCESS:ReturnT.FAIL;
    }


    @Override
    public ReturnT<String> update(UserHotel userHotel) {
        int ret = userHotelMapper.update(userHotel);
        return ret>0?ReturnT.SUCCESS:ReturnT.FAIL;
    }


    @Override
    public UserHotel load(int id) {
        return userHotelMapper.load(id);
    }

    @Override
    public UserHotel getByIdId(int userId, int hotelId) {
        return userHotelMapper.getByIdId(userId, hotelId);
    }


    @Override
    public Map<String,Object> pageList(int offset, int pagesize) {

        List<UserHotel> pageList = userHotelMapper.pageList(offset, pagesize);
        int totalCount = userHotelMapper.pageListCount();

        // result
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("pageList", pageList);
        result.put("totalCount", totalCount);

        return result;
    }

    @Override
    public List<Map<String, Object>> getUserHotelByUserId(int userid) {
        return userHotelMapper.getUserHotelByUserId(userid);
    }

}

